import time

import allure
from selenium.webdriver.common.by import By

from bazhuayun.page.base_octopus_cloud import BaseOctopusCloud
from bazhuayun.utils.log_utils import logger


class HomePageAdd(BaseOctopusCloud):
    _CLICK_NAME = By.XPATH, '(//*[@class="el-input__inner"])[1]'
    _CLICK_PUSH_THE_SHIPMENT = By.XPATH, '//*[@placeholder="任意时间点"]'
    _CLICK_SURE = By.XPATH, '//*[text()="确定"]'
    _CLICK_SHIPMENT_GROUP = By.XPATH, '(//*[@placeholder="请选择"])[4]'
    _CHOOSE_GROUP = By.XPATH, '//*[text()="仓库测试2群"]'
    _CHOOSE_WEIXIN = By.XPATH, '(//*[@class="el-select__input"])[2]'
    _CHOOSE_WEIXIN1 = By.XPATH, '(//*[text()="垚"])[2]'
    _SHIPPING_TEMPLATE = By.XPATH, '(//*[@class="el-input__inner"])[10]'
    _CHOOSE_LA_WAN_LA = By.XPATH, '//*[text()="啦完了"]'
    _CLICK_BTN = By.XPATH, '(//*[text()="提交"])'

    @allure.step("完成添加仓库操作")
    def home_page_add(self, name):
        # 点击名称
        time.sleep(2)
        self.find_ele(*self._CLICK_NAME).click()
        time.sleep(2)
        self.find_ele(*self._CLICK_NAME).send_keys(name)
        # 推发货表格
        self.find_ele(*self._CLICK_PUSH_THE_SHIPMENT).click()
        # 点击确认
        time.sleep(2)
        self.find_ele(*self._CLICK_SURE).click()
        # 点击发货群
        self.find_ele(*self._CLICK_SHIPMENT_GROUP).click()
        # 选择测吧
        time.sleep(2)
        self.find_ele(*self._CHOOSE_GROUP).click()
        # 点击打单人微信号
        time.sleep(2)
        self.find_ele(*self._CHOOSE_WEIXIN).click()
        # 选择微信号
        self.find_ele(*self._CHOOSE_WEIXIN1).click()
        # 发货模板
        time.sleep(2)
        self.find_ele(*self._SHIPPING_TEMPLATE).click()
        # 选择拉完了
        time.sleep(2)
        self.find_ele(*self._CHOOSE_LA_WAN_LA).click()
        # 点击提交
        self.find_ele(*self._CLICK_BTN).click()
        logger.info("完成添加仓库操作")

        from bazhuayun.page.homepage import HomePage
        return HomePage(self.driver)


